package com.sd.h3.carrental.servlet;




import com.sd.h3.carrental.bean.intf.LoginRemote;


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletException;
import javax.ejb.EJB;
import java.io.IOException;

public class SignonServlet extends HttpServlet {

    @EJB
    private LoginRemote loginRemote;


 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException {

        String username = request.getParameter("user");
        String pass = request.getParameter("password");
        try{
            int loginResponse = loginRemote.login(username, pass);
            switch(loginResponse){
                case 1:
                    request.getRequestDispatcher("/jsp/loginsuccessadmin.jsp").forward(request, response);
                    break;
                case 2:
                    request.getRequestDispatcher("/jsp/loginsuccessuser.jsp").forward(request, response);
                    break;
                default:
                    request.getRequestDispatcher("/jsp/loginfail.jsp").forward(request, response);
                    break;

            }
        } catch (Exception ex) {
            throw new ServletException(ex);

        }

    }


    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

}